#!/usr/bin/env python
#coding=utf-8


# 列表 []  可以更改  () 元组 不可更改

aList = [1,2,3,4]
print aList

# 字典
aDict = {'host' : 'earth'} # create dict 
aDict['port'] = 80
print aDict

print aDict.keys()

print aDict['host']

for key in aDict:
    print key, aDict[key]

# if
if 2>1:
    print 2 > 1

# while
count = 2
while count:
    count-=1
    print count

# print 换行
for item in ['e-mail', 'net-surfing', 'homework', 'char']:
    print item


for item in ['e-mail', 'net-surfing', 'homework', 'char']:
    print item,
print

foo = 'abc'
for i in range(len(foo)):
    print foo[i], i

# 列表解析
squared = [x ** 2 for x in range(4)]
for i in squared:
    print i

sqdEvens = [x**2 for x in range(8) if not x % 2]
for i in sqdEvens:
    print i

#filename = raw_input('Enter file name: ')
#handle = open(filename, 'r')
#for eachLine in handle:
#	print eachLine,
#handle.close()


#try:
#	filename = raw_input('Enter filename : ')
#	fobj = open(filename, 'r')
#	for eachLine in fobj:
#		print eachLine,
#	fobj.close()
#except IOError, e:
#	print 'file open error: ', e

# 函数
def add(x):
	return (x + x)

print add(100)

## 默认参数

def foo(debug=True):
	if debug:
		print 'in debug mode'
	print 'done'

foo(False)










